package executors.completable.future;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class ThenRunTest001 {
  public static void main(String[] args) {
    ExecutorService executors = Executors.newCachedThreadPool();
    
    CompletableFuture.runAsync(() -> {
      System.out.println("线程 1 ...");
      System.out.println(Thread.currentThread().getName());
      try {
        TimeUnit.SECONDS.sleep(1);
      } catch (InterruptedException e) {
        throw new RuntimeException(e);
      }
    }, executors).thenRunAsync(() -> {
      System.out.println("线程 2 ...");
      System.out.println(Thread.currentThread().getName());
      
      try {
        TimeUnit.SECONDS.sleep(1);
      } catch (InterruptedException e) {
        throw new RuntimeException(e);
      }
    }, executors).thenRunAsync(() -> {
      System.out.println("线程 3 ...");
      System.out.println(Thread.currentThread().getName());
      
      try {
        TimeUnit.SECONDS.sleep(1);
      } catch (InterruptedException e) {
        throw new RuntimeException(e);
      }
    });
  }
}
